from flask import Flask, request, jsonify
from flask_cors import CORS
import paddlehub as hub

app = Flask(__name__)
CORS(app)

# 加载翻译模型
model = hub.Module(name='transformer-tiny-en2zh')

@app.route('/translate', methods=['POST'])
def translate():
    text = request.json['text']
    result = model.predict([text])
    return jsonify({'translation': result[0]})

if __name__ == '__main__':
    app.run(port=5000)